<template>
	<div style="position: relative;">
		<Row>
	        <Col span="24"  style="text-align: center;">
	            <Card style="width:880px;margin: auto;">
	                <p slot="title"><slot></slot></p>
	                <Row style="text-align: center;margin-top:15px;">
					    <Col span="12" >
				        	<span>科目：</span>
				        	<Select disabled v-model="importsubjectid" style="width:200px"  >
				        		<Option v-for="item in importsubjectlist" :key="item.value" :value="item.value">{{item.label}}</Option>
						    </Select>
				        </Col>
				        <Col span="12" >
				        	<span>科目长：</span>
				            <Select :clearable=true v-model="subjectleader" filterable placeholder="输入快速匹配" style="width:200px">
				                <Option v-for="item in allteacherlist" :value="item.value" :key="item.value">{{ item.label }}</Option>
				            </Select>
				        </Col>
			        </Row>
			        <Row style="text-align: center;margin-top:15px;">
					    <Col span="12" >
				        	<span>校级：</span>
				            <Select :clearable=true v-model="schoollevel" filterable placeholder="输入快速匹配" style="width:200px">
				                <Option v-for="item in schoollevellist" :value="item.value" :key="item.value">{{ item.label }}</Option>
				            </Select>
				        </Col>
				        <Col span="12" >
				        	<span>学部级：</span>
				            <Select :clearable=true v-model="learnpartlevel" filterable placeholder="输入快速匹配" style="width:200px">
				                <Option v-for="item in learnpartlevellist" :value="item.value" :key="item.value">{{ item.label }}</Option>
				            </Select>
				        </Col>
			        </Row>
			        <Row style="text-align: center;margin-top:15px;">
					    <Col span="12" >
				        	<span>年段级：</span>
				            <Select :clearable=true v-model="yearsegmentlevel" filterable placeholder="输入快速匹配" style="width:200px">
				                <Option v-for="item in yearsegmentlevellist" :value="item.value" :key="item.value">{{ item.label }}</Option>
				            </Select>
				       </Col>
			        </Row>
	                <Row>
				    	<Col span="24" style="margin-top:15px">
				    		<Button type="ghost" @click="chance" icon="close-round">取消</Button>
				    		<Button type="primary" @click="savesubjectleader" icon="checkmark-round">保存</Button>
				    	</Col>
				    </Row>
	            </Card>
	        </Col>
	    </Row>
	     <Spin size="large" fix v-if="loadingShow"></Spin>
	</div>
</template>

<script>
	import api from "@/components/js/Apidomain.js"
	
	export default{
		props:{
			importsubjectlist: {
		        type: Array,
		        default: function () {return []}
		   	},
			importsubjectid:"",		//父组件传来的科目的id
		},
		data(){
			return{
				loadingShow:false,			//控制面板的加载中的显示和隐藏
				
				subjectleader:"",					//从老师当中选择的科目长
				schoollevel:"",						//校级选择
				learnpartlevel:"",					//学部级选择
				yearsegmentlevel:"",				//年段级选择	
				
				allteacherlist:[
//				  	{value: '1',label: 'New York'},
//                  {value: '2',label: 'London'},
//                  {value: '3',label: 'Sydney'},
				],
				schoollevellist:[
//				  	{value: '1',label: 'New York'},
//                  {value: '2',label: 'London'},
//                  {value: '3',label: 'Sydney'},
				],
				learnpartlevellist:[
					{value: '1',label: 'New York'},
                    {value: '2',label: 'London'},
                    {value: '3',label: 'Sydney'},
				],
				yearsegmentlevellist:[
					{value: '1',label: 'New York'},
                    {value: '2',label: 'London'},
                    {value: '3',label: 'Sydney'},
				]
			}
		},
		created(){
			this.getallteacherlist();
			this.getschoollevellist();
			this.getlearnpartlevellist();
			this.getyearsegmentlevellist();
		},
		methods:{
			chance:function(){
				this.$emit('chance')
			},
			savesubjectleader:function(){
				if(this.importsubjectid == "" || this.subjectleader == "" ){
					self.$Message.error({
							content: "请完善信息后再提交",
							duration: 10,
							closable: true
						});	
					return;
				}
				var senddata = {
					"id":"",
					"subjectId":this.importsubjectid,
					"teacherId":this.subjectleader,
					"atSchoolId":this.schoollevel,
					"atDeptId":this.learnpartlevel,
					"atGradeId":this.yearsegmentlevel
				}
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/addSubjectLeader';
            	this.$http.post(url,senddata).then(function(response) {
					if(response.data.success == true){
						self.$Message.success({
		                    content: '保存成功',
		                    duration: 10,
		                    closable: true
               			})
						self.$emit('chance')
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00011',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			getallteacherlist:function(){
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getTchTeacherSelectList';
            	this.$http.post(url,{}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.allteacherlist = response.data.data
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00012',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			getschoollevellist:function(){
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getCurSchoolInfo';
            	this.$http.post(url,{}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.schoollevellist.push(response.data.data);
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00013',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			getlearnpartlevellist:function(){
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getTchDepartmentSelectList';
            	this.$http.post(url,{}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.learnpartlevellist = response.data.data;
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00014',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			getyearsegmentlevellist:function(){
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchStudent/getTchGradeSelect';
            	this.$http.post(url,{}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.yearsegmentlevellist = response.data.data;
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00015',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
		}
	}
</script>

<style>
</style>